<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="decorator" content="default" />
<title>报告附页管理</title>
	<style>
		.pagination{background:#fff;position:relative;margin:0;top:-8px;padding:10px 0;}
		.pagination ul{float:right;box-shadow:none;}
	</style>
<script type="text/javascript">
	function page(n, s) {
		$("#pageNo").val(n);
		$("#pageSize").val(s);
		$("#searchForm").submit();
		return false;
	}
	function loadSubProject(projectId) {
		if(!projectId) {
			$('#subPro').html('<option value="">请选择单位工程</option>');
			$('#subPro').select2('val','');
			return;
		}
		$.post(
			'${ctx}/project/subProject/listSubByPro',	
			{projectId: projectId},
			function(data, textStatus, jqXHR) {
				var html = '<option value="">请选择单位工程</option>';
				for(var i=0;i<data.length;i++) {
					html+= '<option value="'+data[i].id+'">'+data[i].name+'</option>';
				}
				$('#subPro').html(html);
				$('#subPro').val('${fy.subProject.id}').trigger('change');
			},'json');
		
	}
	
	$(function() {
		$('#projectId').val('${fy.project.id}').trigger('change');
	});
</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/project/fy/list?jjbh=${fy.jjbh}&gg=${fy.gg}&hkbh=${fy.hkbh}">报告附页列表</a></li>
		<%-- <li><a href="${ctx}/project/fy/form">报告附页添加</a></li> --%>
	</ul>
	<form:form id="searchForm" modelAttribute="fy"
		action="${ctx}/project/fy/list" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}" />
		<input id="pageSize" name="pageSize" type="hidden"
			value="${page.pageSize}" />
		<input name="project.id" type="hidden" value="${fy.project.id}">
		<input name="subProject.id" type="hidden" value="${fy.subProject.id}">
		<label>管线编号：</label>
		<form:input path="jjbh" htmlEscape="false"/>
		&nbsp;
		<label>规格 ：</label>
		<form:input path="gg" htmlEscape="true"/>
		&nbsp;
		<label>焊口编号 ：</label>
		<form:input path="hkbh" htmlEscape="false"/>
		&nbsp;
		<%--<label>未评定结果：</label>--%>
		<%--<form:checkbox path="pdjgnull"/>--%>
		<%--<label>有缺陷：</label>
		<form:checkbox path="hasError"/>
		&nbsp;--%>
		<input id="btnSubmit" class="btn btn-primary" type="submit" value="查询"/>	
	</form:form>
	<common:message content="${message}" />
	<table id="contentTable"
		class="table table-striped table-bordered table-condensed">
		<thead>
			<tr>
				<shiro:hasPermission name="fy:batch">
					<th>选择</th>
				</shiro:hasPermission>
				<th>工程名称</th>
				<th>单位工程</th>
				<th>检件名称</th>
				<th>管线编号</th>
				<th>焊口编号</th>
				<th>片号</th>
				<th>规格</th>
				<th>缺陷性质</th>
				<th>缺陷定量</th>
				<th>评定结果</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
			<c:forEach items="${page.list}" var="fy">
				<tr>
					<shiro:hasPermission name="fy:batch">
					<td>
						<input name="items" type="checkbox" value="${fy.id}" />
					</td>
					</shiro:hasPermission>
					<td>${fy.project.name}</td>
					<td>${fy.subProject.name}</td>
					<td>${fy.jjmc}</td>
					<td>${fy.jjbh}</td>
					<td><a href="${ctx}/project/fy/form?id=${fy.id}">${fy.hkbh}</a></td>
					<td>${fy.ph}</td>
					<td>${fy.gg}</td>
					<td>${fy.qxxz}</td>
					<td>${fy.qxdl}</td>
					<td>${fns:getDictLabel(fy.pdjg, 'dict_fy_pdjg', '')}</td>
					<td>
						<a href="${ctx}/project/fy/form?id=${fy.id}">修改</a> 
						<a href="${ctx}/project/fy/form?id=${fy.id}&notnew=yes">继续添加</a>
						<a href="${ctx}/project/fy/delete?id=${fy.id}&project.id=${fy.project.id}&subProject.id=${fy.subProject.id}" onclick="return confirmx('确认要删除该记录吗？', this.href)">删除</a>
					</td>
				</tr>
			</c:forEach>
		</tbody>
	</table>
	<div id="spots" class="pagination">
		<shiro:hasPermission name="fy:batch">
		<input class="btn btn-primary" type="button" value="全选" id="selectAll" />
		<input class="btn btn-primary" type="button" value="全不选" id="unSelect" />
		<input class="btn btn-primary" type="button" value="反选" id="reverse" />&nbsp;&nbsp;&nbsp;&nbsp;
		<input class="btn btn-primary" type="button" id="batchQXXZ" value="缺陷性质" onclick="toBatchForm('qxxz')"/>
		<input class="btn btn-primary" type="button" id="batchQXDL" value="缺陷定量" onclick="toBatchForm('qxdl')"/>
		<input class="btn btn-primary" type="button" id="batchPDJG" value="评定结果" onclick="toBatchForm('pdjg')"/>
		</shiro:hasPermission>
		${page}
	</div>

<script>

	$(function () {
		$("#selectAll").click(function () {//全选
			$("#contentTable :checkbox").attr("checked", true);
		});

		$("#unSelect").click(function () {//全不选
			$("#contentTable :checkbox").attr("checked", false);
		});

		$("#reverse").click(function () {//反选
			$("#contentTable :checkbox").each(function () {
				$(this).attr("checked", !$(this).attr("checked"));
			});
		});
	});

	function toBatchForm(type, fyId) {
		if(!fyId) {
			fyId = '';
			$("[name=items]:checkbox:checked").each(function(){
				fyId+=$(this).val()+",";
			});
			if(!fyId) {
				showTip('请选择要处理的数据','error');
				return false;
			}
		}
		top.$.jBox.open("iframe:${ctx}/project/fy/toBatchForm", "批量操作", 500, 400,
			{
				ajaxData: {
					'type': type
				},
				buttons:{"确定":"ok","关闭":true},
				submit:function(v, h, f){
					if (v=="ok"){
						var $_iframe = h.find("iframe")[0].contentWindow.$;
						if(!$_iframe)return;
						var valueForUpdate = $_iframe('#'+type).val();
						if(!valueForUpdate) {
							showTip('请选择要更新的目标状态','error');
							return false;
						}
						var param = {
							'fyId': fyId,
							'type': type,
							'value': valueForUpdate
						}
						updateFyInfo(param);
					}
				},
				loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});

	}

	function updateFyInfo(param) {
		console.log(param);
		$.post(
				'${ctx}/project/fy/batchUpdate',
				param,
				function(data, status) {
					if(data && data.status && data.status=='success') {
						showTip(data.message,'success');
						window.location.reload();
					}else {
						showTip(data.message,'error');
					}
				}
		);


	}

</script>
</body>
</html>